package com.exam.t;

public class Solution {
	public int removeElement(int[] nums, int val) {
		if (nums.length == 0) {
			return 0;
		}
		int lenNew = nums.length;
		if (nums[nums.length - 1] == val) {
			lenNew = nums.length - 1;
		}
		if (nums.length == 1) {
			return lenNew;
		}
		for (int i = nums.length - 2; i >= 0; i--) {
			if (nums[i] == val) {
				int temp = nums[lenNew - 1];
//    			nums[lenNew-1]=nums[i];
				nums[i] = temp;
				lenNew--;
			}

		}
		return lenNew;
	}
}